home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
lib
/
filepath.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
6KB
|
190 lines
; $Id: filepath.pro,v 1.16 1997/01/15 03:11:50 ali Exp $
;
; Copyright (c) 1989-1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;
FUNCTION FILEPATH, FILENAME, ROOT_DIR=root_dir, SUBDIRECTORY=subdir, $
TERMINAL = TERMINAL, TMP = TMP
;+
; NAME:
; FILEPATH
;
; PURPOSE:
; Given the name of a file in the IDL distribution,
; FILEPATH returns the fully-qualified path to use in
; opening the file. Operating system dependencies
; are taken into consideration. This routine is used by RSI to
; make the User Library portable.
;
; CATEGORY:
; File Management.
;
; CALLING SEQUENCE:
; Result = FILEPATH('filename' [, SUBDIRECTORY = subdir])
;
; INPUTS:
; filename: The lowercase name of the file to be opened. No device
; or directory information should be included.
;
; KEYWORDS:
; ROOT_DIR: The name of the directory from which the resulting path
; should be based. If not present, the value of !DIR is used.
; This keyword is ignored if TERMINAL or TMP are specified.
;
; SUBDIRECTORY: The name of the subdirectory in which the file
; should be found. If this keyword is omitted, the main
; directory is used. This variable can be either a scalar
; string or a string array with the name of each level of
; subdirectory depth represented as an element of the array.
;
; For example, to get a path to the file DETERM in the "userlib"
; subdirectory to the IDL "lib" subdirectory, enter:
;
; path = FILEPATH("determ", SUBDIRECTORY = ["lib", "userlib"])
;
; TERMINAL: Return the filename of the user's terminal.
;
; TMP: The file is a scratch file. Return a path to the
; proper place for temporary files under the current operating
; system.
;
; OUTPUTS:
; The fully-qualified file path is returned. If one of the subdirectory
; keywords is not specified, the file is assumed to exist in the
; main distribution directory.
;
; COMMON BLOCKS:
; None.
;
; RESTRICTIONS:
; Don't specify more than one of the keywords in a single call.
;
;
; EXAMPLE:
; To get a path to the file DETERM in the "userlib" subdirectory to the
; IDL "lib" subdirectory, enter:
;
; path = FILEPATH("determ", SUBDIRECTORY = ["lib", "userlib"])
;
; The variable "path" contains a string that is the fully-qualified file
; path for the file DETERM.
;
; MODIFICATION HISTORY:
; December, 1989, AB, RSI (Formalized from original by DMS)
; October, 1990, SG, RSI (added support for MSDOS)
; February, 1991, SMR, RSI (added string array support for multi-level
; directories)
; 21 April 1993, AB, Added ROOT_DIR keyword.
; 14 July 1994, KDB, RSI - Corrected logic error in VMS section
; of the ROOT_DIR keyword. Any
; sub-directory specification was
; being ignored when using ROOT_DIR. Fixed.
; March, 1995, DJE, Add a ':' if root_dir is specified on the Mac.
; 29 July 1995, Robert.M.Candey.1@gsfc.nasa.gov, Changed VMS case for
; no specified path to not append '.][000000]'
; April, 1996, DJE, Remove call to STRLOWCASE(SUBDIR).
; August, 1996, AJH, used environment variables to define TMP on Win32
;-
ON_ERROR,2 ;Return to caller if an error
;occurs
do_tmp = KEYWORD_SET(TMP) ;get temporary path if existing
path = ''
IF (KEYWORD_SET(TERMINAL)) THEN BEGIN
CASE !VERSION.OS OF
'vms': RETURN,'SYS$OUTPUT:'
'Win32': BEGIN
PRINT, "No terminal device available for Windows"
RETURN, ''
END
'MacOS' : BEGIN
PRINT, "No terminal device for the Mac"
RETURN, ''
END
ELSE: RETURN,'/dev/tty'
ENDCASE
ENDIF
IF (do_tmp) THEN BEGIN
CASE !VERSION.OS OF
'vms': root_dir = 'SYS$LOGIN:'
'Win32': BEGIN
root_dir = getenv('TMP')
IF (strtrim(root_dir, 2) EQ "") THEN BEGIN
root_dir = GETENV('TEMP')
IF (strtrim(root_dir, 2) EQ "") THEN BEGIN
root_dir = GETENV('WINDIR')
IF (strtrim(root_dir, 2) EQ "") THEN root_dir = '\tmp'
ENDIF
ENDIF
END
'MacOS': begin
root_dir = !DIR
if (n_params() EQ 0) then filename = "IDL Temp File"
end
ELSE: root_dir = '/tmp'
ENDCASE
ENDIF ELSE BEGIN
IF (not KEYWORD_SET(ROOT_DIR)) THEN root_dir = !DIR
IF (KEYWORD_SET(SUBDIR)) THEN BEGIN ;if the SUBDIR keyword is set
;then include each level in the
CASE !VERSION.OS OF ;path separated by the correct
'vms': divider = "." ;directory level delimiter for
'Win32': divider = "\" ;the current O.S.
'MacOS' : divider = ":"
ELSE: divider = "/"
ENDCASE
FOR i = 0, N_ELEMENTS(SUBDIR) - 1 DO BEGIN
path = path + SUBDIR[i]
IF(i NE N_ELEMENTS(SUBDIR) - 1) THEN $
path = path + divider
ENDFOR
if !VERSION.OS EQ 'MacOS' THEN path = path + divider
ENDIF
ENDELSE
CASE !VERSION.OS OF
'vms': BEGIN
IF (NOT do_tmp) THEN BEGIN
IF (path EQ '') THEN begin
case 1 of
strmid(root_dir, strlen(root_dir)-2, 2) eq ".]": $
root_dir = strmid(root_dir,0,strlen(root_dir)-2) +']' ; remove .
strmid(root_dir, strlen(root_dir)-1, 1) eq "]": ; nothing
else: path = '[000000]' ; assume implicit '.]' or device in root_dir
endcase
ENDIF ELSE BEGIN ; path is filled
path = '[' + path + ']'
; check for a ".]" at the end of our root directory
IF(( strmid(root_dir, strlen(root_dir)-2, 2) ne ".]") and $
( strmid(root_dir, strlen(root_dir)-1, 1) eq "]") )then $
root_dir = strmid(root_dir,0,strlen(root_dir)-1) +'.]'
; if no ']' at end of root_dir, assume implicit '.]' or device
ENDELSE
ENDIF
END
'Win32': BEGIN
path = '\' + path
IF (path NE '\') THEN path = path + '\'
END
'MacOS': BEGIN
; make sure the root dir ends with a separator
IF (STRMID(root_dir, STRLEN(root_dir) - 1, 1) NE ':') THEN $
root_dir = root_dir + ':'
END
ELSE: BEGIN
path = '/' + path
IF (path NE '/') THEN path = path + '/'
END
ENDCASE
RETURN, root_dir + path + filename
END